<?php
class Application_Model_RESTWSManager
{
    public static function getData ($path, $parameters = NULL)
    {
        $options = Zend_Registry::get("webOptions");
        $restOpt = $options["REST"];
        $uri = $restOpt["uri"];
        $key = $restOpt["api_key"];
        if (is_array($parameters)) {
            $parameters["api_key"] = $key;
        } else {
            $parameters = array("api_key" => $key);
        }
        try {
            $client = new Zend_Rest_Client($uri);
            $repone = $client->restGet($path, $parameters);
            $body = $repone->getBody();
            $xmlData = new Zend_Config_Xml($body);
            $originalData = $xmlData->toArray();
            $data=self::processItemEmptyField($originalData);
        } catch (Exception $e) {
            Application_Model_LogManager::wirtelog($e->getMessage());
        }
        return $data;
    }
    private static function processItemEmptyField ($item)
    {
        if (is_array($item)) {
            $keys = array_keys($item);
            foreach ($keys as $aKey) {
                if (is_array($item[$aKey])) {
                    $item[$aKey] = self::processItemEmptyField($item[$aKey]);
                } else {
                    $temp = $item[$aKey];
                    if (is_string($temp)) {
                        if ("None" == $temp) {
                            $item[$aKey] = "";
                        }
                    }
                }
            }
        }
        return $item;
    }
}

